#include "TextureManager.h"
#include <map>
#include <iostream>

using namespace std;
		
std::auto_ptr<TextureManager> manager;

TextureManager::TextureManager()
{
}

SpriteSheet* TextureManager::loadSpriteSheet(const std::string& textureName)
{
	// possibly read from file all the necessary variables
	SpriteSheet* ss = new SpriteSheet(textureName, 32, 40, 2, 2);
	return ss;
}


SpriteSheet* TextureManager::getSpriteSheet(const std::string& textureName)
{
	map<string, SpriteSheet* >::iterator it = textureMap.find(textureName);
	if (it != textureMap.end())
	{
		return it->second;
	}
	else
	{
		SpriteSheet* newSheet = loadSpriteSheet(textureName);
		
		textureMap.insert( pair<string, SpriteSheet* >( textureName, newSheet ) );
		return newSheet;
	}
}

TextureManager* TextureManager::getInstance()
{
	if ( ! (manager.get()) )
		manager = auto_ptr<TextureManager>( new TextureManager() );
	
	return manager.get();
}
